package tv.youxing.android.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;

import com.kaopiz.kprogresshud.KProgressHUD;
import com.xiasuhuei321.loadingdialog.view.LoadingDialog;

/**
 * Created by Administrator on 2017/6/14.
 */

public abstract class BaseFragment extends Fragment {



    private LoadingDialog mLoadingDialog;
    private KProgressHUD hud;




    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }


    protected void showDialog(Activity activity, boolean isShow) {
        if (mLoadingDialog == null) {
            mLoadingDialog = new LoadingDialog(activity);
        }
        if (mLoadingDialog != null) {
            mLoadingDialog.setLoadingText("加载中")
                    .setSuccessText("加载成功")//显示加载成功时的文字
                    //.setFailedText("加载失败")
                    .setInterceptBack(true)
                    .setLoadSpeed(LoadingDialog.Speed.SPEED_TWO)
                    .setRepeatCount(1);
        }
        if (isShow) {
            mLoadingDialog.show();
        } else {
            mLoadingDialog.close();
        }

    }

    public void showProgress(String message)
    {
        if(hud==null)
        {
            hud = KProgressHUD.create(getContext())
                    .setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
                    .setLabel(message)
                    .setCancellable(true);
        }
        if(!hud.isShowing())
        {
            hud.show();
        }
    }
    public void hideProgress()
    {
        if(hud != null && hud.isShowing())
        {
            hud.dismiss();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();

        //检查内存泄露
//        RefWatcher refWatcher = BaseApplication.getRefWatcher(getActivity());
//        refWatcher.watch(this);
    }
}
